using System;
using System.IO;
using ADODB;

namespace Exchange.Export.MHTMLHelper
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class ExtractMailAsMHTML
	{
		public ExtractMailAsMHTML()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		private string folderName=Path.GetTempPath();

		/// <summary>
		/// This is the name of the temporary folder that will be used
		/// </summary>
		public string FolderName
		{
			get
			{
				return folderName;
			}
			set
			{
				folderName=value;
			}
		}
		private string destfolderName=Path.GetTempPath();

		/// <summary>
		/// This is the name of the temporary folder that will be used
		/// </summary>
		public string DestFolderName
		{
			get
			{
				return destfolderName;
			}
			set
			{
				destfolderName=value;
			}
		}
		private string fileName="";

		/// <summary>
		/// This is the name of the temporary folder that will be used
		/// </summary>
		public string FileName
		{
			get
			{
				return fileName;
			}
			set
			{
				fileName=value;
			}
		}
		private string destfileName="";

		/// <summary>
		/// This is the name of the temporary folder that will be used
		/// </summary>
		public string DestFileName
		{
			get
			{
				return destfileName;
			}
		}

		/// <summary>
		/// This method saves the MHTM file
		/// </summary>
		public bool Save()
		{
			CDO.MessageClass message = new CDO.MessageClass();
			message.CreateMHTMLBody("file://"+FolderName+"\\"+FileName+".htm", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
            
			ADODB.Stream stream = (ADODB.Stream)message.GetStream();
			destfileName=DestFolderName+"\\"+FileName+".mhtml";
			stream.SaveToFile(destfileName, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
			return true;
		}
	}
}
